/*
 * chunk.h
 *
 *  Created on: Mar 29, 2013
 *      Author: root
 */

#ifndef CHUNK_H_
#define CHUNK_H_

#include "stdnet.h"

/*
*this is define chunk trans protocal
*can usr tcp/udp to trans chunk
*
*
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*+---streamid--+--fmt--+--year--+--month--+--day--+--clip index--+--chunk index--+--length--+--data--+
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* chunk header length = 2 +1+ 2+1+1+2 + 8 + 3 = 20 bytes
*
* streamid: 0~ 0xffff
* fmt: 0~ 0xff
* year: 0~0xffff
* month: 0~0xff
* day: 0~0xff
* clip_index: 0~ 0xffff
* index:0~0xffffffffffffffff
* length/offset:0~0xffffff, uint24, 3 bytes
*
*/
#define CHUNK_HEADER_LEN 20
/*
*chunk struct
*define
*/
#pragma pack(1)
struct chunk
{
	uint16_t streamid;/*stream id :data stream ID*/
	uint8_t  fmt;/*data chunk fmt*/
	uint16_t clip_index;/*data clip index*/
	uint64_t index;/*data chunk index*/
	uint24_t length;/*data chunk length,uint24 ,3 bytes,contain chunk header length + data leng = pdata length*/

	uint8_t  *pData;/*data ptr to buf*/
	uint24_t offset;/*data chunk opration offset,uint24 ,3 bytes*/
	uint24_t buf_size;/*data buf max size*/
	uint8_t  chunk_head_len;/*data chunk header length*/

	uint16_t tm_year;/*year*/
	uint8_t	 tm_month;/*month,1~12*/
	uint8_t	 tm_day;/*day ,1~31*/

	/*
	* chunk list define
	*/
	chunk * next;
	chunk * prev;
	/*
	*init chunk
	*/
	chunk()
	{
		streamid = 0;
		fmt = 0;
		clip_index = 0;
		index= 0;
		length = 0;

		pData = NULL;
		offset = 0;
		buf_size = 0;
		chunk_head_len = CHUNK_HEADER_LEN;

		tm_year = 0;
		tm_month = 0;
		tm_day = 0;

		next = NULL;
		prev = NULL;
	}
};

#pragma pack()
typedef chunk *  pchunk;


#endif /* CHUNK_H_ */
